<?php

$params = require(__DIR__ . '/params.php');
$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'charset' => 'utf-8',
    'language' => 'zh-CN',  //全局设置为中文--推荐
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm' => '@vendor/npm-asset',
        'wpjCode/wii' => '@runtime/wpjCode/wii/src/',
        // 文件上传存放主目录
        '@uploadPath' => $params['uploadPath'],
        // 模板存放主目录
        '@template' => $params['frontTempPath'],
    ],
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'uM7_kiYGawmDi_2DoFAi1OkaQnE6Db2F',
            "enableCsrfValidation" => false
        ],
        'session' => [
            'name' => 'f23bd81', // session 名称防止多项目混合
            'savePath' => dirname(__DIR__) . '/runtime/session', // 规定session保存目录
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache'
        ],
        'memcache' => [
            'class' => 'yii\caching\MemCache',
            'servers' => [
                [
                    'host' => $_SERVER['MEM_HOST'],
                    'port' => $_SERVER['MEM_PORT'],
                    'weight' => $_SERVER['MEM_WEIGHT']
                ]
            ],
            'useMemcached' => true // 是否开启[memcached]
        ],
        'redis' => [ // 其他缓存专用，比如：文章数据统计等非数据库数据
            'class' => 'yii\redis\Connection',
            'hostname' => $_SERVER['REDIS_HOST'],
            'port' => $_SERVER['REDIS_PORT'],
            'database' => $_SERVER['REDIS_DB'],
            'password' => $_SERVER['REDIS_PWD']
        ],
        'redisDb' => [ // 数据库Redis缓存专用
            'class' => 'yii\redis\Connection',
            'hostname' => $_SERVER['REDIS_HOST'],
            'port' => $_SERVER['REDIS_PORT'],
            'database' => $_SERVER['REDIS_DB'],
            'password' => $_SERVER['REDIS_PWD']
        ],
        'user' => [
            'identityClass' => 'app\modules\front\model\User',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
            'idParam' => '__user',
            'loginUrl' => '/login.1html?showHint=1',
        ],
        'admin' => [
            'class' => 'yii\web\User',
            'identityClass' => 'app\modules\backend\model\UserLoginModel',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
            'idParam' => '__admin',
            'loginUrl' => '/admin/login.html?showHint=1',
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'useFileTransport' => false,//这句一定有，false发送邮件，true只是生成邮件在runtime文件夹下，不发邮件
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.126.com',  //每种邮箱的host配置不一样
                'username' => '', // 邮件账号
                'password' => '', // 邮件密码
                'port' => '25',
                'encryption' => 'tls',

            ],
            'messageConfig' => [
                'charset' => 'UTF-8',
                'from' => ['wangpengjie369@126.com' => 'admin']
            ],
        ],
        'log' => require(__DIR__ . '/log.php'),
        'db' => require __DIR__ . '/db.php',
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => array_merge(
                require(__DIR__ . '/router/backendPage.php'),
                require(__DIR__ . '/router/backendApi.php'),
                require(__DIR__ . '/router/front.php')
            )
        ],
        'assetManager' => [
            'bundles' => [
                'yii\web\JqueryAsset' => [
                    'sourcePath' => null,
                    'js' => []
                ],
            ],
        ],
        'view' => [
            'renderers' => [
                'tpl' => [
                    'class' => 'yii\smarty\ViewRenderer',
                    'cachePath' => '@runtime/smarty/front/cache',
                    'compilePath' => '@runtime/smarty/front/compile',
                    'options' => [
                        'left_delimiter' => '{',
                        'right_delimiter' => '}',
                        'caching' => false, // 开启缓存 - 不要开缓存了，开了之后一个文章一个缓存，头部更多
                        'cache_lifetime' => 3600, // 缓存过期时间
                        'cache_id' => $_SERVER["REQUEST_URI"]
                    ],
                    'widgets' => [
                        'blocks' => [
                            'NewsCategory' => 'app\service\tag\NewsCategory',
                            'Position' => 'app\service\tag\Position',
                        ],
                        'functions' => [
                            'convertTools' => 'app\service\tool\ConvertService',
                            'fileTools' => 'app\service\tool\FileService',
                            'generateTools' => 'app\service\tool\GenerateService',
                            'requestTools' => 'app\service\tool\RequestService',
                            'utilsTools' => 'app\service\tool\UtilsService',
                            'GetBlock' => 'app\service\tag\GetBlock',
                            'GetSetting' => 'app\service\tag\GetSetting',
                        ],
                    ],
                ],
            ],
        ],
    ],
    'params' => require __DIR__ . '/params.php',
    'modules' => require(__DIR__ . '/modules.php')
];

if (YII_ENV_DEV) {
//     configuration adjustments for 'dev' environment
//    $config['bootstrap'][] = 'debug';
//    $config['modules']['debug'] = [
//        'class' => 'yii\debug\Module',
//        // uncomment the following to add your IP if you are not connecting from localhost.
//        'allowedIPs' => ['*'],
//    ];

    $config['bootstrap'][] = 'wii';
    $config['modules']['wii'] = [
        'class' => 'wpjCode\wii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        'allowedIPs' => ['*'],
    ];
}

return $config;
